package com.desktopmng.service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.desktopmng.orm.CalendarPO;

public class CalendarManager extends HibernateEntityDao<CalendarPO> {

	@SuppressWarnings("unchecked")
	public List<CalendarPO> queryCalendars(Date qstart, Date qend, String userId) {
		String hql = "from CalendarPO where userId = ? and startTime >= ? and startTime < ?";
		List<Object> values = new ArrayList<Object>();
		values.add(userId);
		values.add(new Timestamp(qstart.getTime()));
		values.add(new Timestamp(qend.getTime()));
		List<CalendarPO> list = find(hql, values.toArray());
		return list;
	}
	
	public Long addCalendar(CalendarPO c) {
		this.save(c);
		return c.getId();
	}
	
	public void addCalendarBatch(List<CalendarPO> list) {
		for (CalendarPO c : list) {
			this.save(c);
		}
	}
	
	public CalendarPO getCalendar(Long id) {
		return get(id);
	}
	
	public void updateCalendar(CalendarPO c) {
		this.merge(c);
	}
	
	public void deleteCalendar(Long id) {
		this.removeById(id);
	}
}
